package com.imooc.ecommerce.stream;

import com.alibaba.fastjson.JSON;
import com.imooc.ecommerce.vo.QinyiMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;

/**
 * 使用默认的信道实现消息的接收
 *
 * @author zhangshao
 * @since 2023/12/10 22:51
 */
@Slf4j
@EnableBinding(Sink.class)
public class DefaultReceiveService {
    /**
     * 使用默认的输入信道接收消息
     *
     * @param payload
     */
    @StreamListener(Sink.INPUT)
    public void receiveMessage(Object payload) {
        log.info("in DefaultReceiveMessage start");
        QinyiMessage qinyiMessage = JSON.parseObject(payload.toString(), QinyiMessage.class);
        //消费消息
        log.info("in DefaultReceiveService consume message success : [{}]", JSON.toJSONString(qinyiMessage));
    }
}
